//
//  InChannelSoundCollectionReusableView.m
//  Inner  Voice
//
//  Created by Martin.Wang on 16/2/29.
//  Copyright © 2016年 徐海宇. All rights reserved.
//

#import "InChannelSoundCollectionReusableView.h"

#import "InSoundFavouriteTool.h"

#import <UMSocial.h>
@interface InChannelSoundCollectionReusableView()<UMSocialUIDelegate>


@end

@implementation InChannelSoundCollectionReusableView

- (void)awakeFromNib {
    
    self.channelImage.image = [UIImage imageNamed:@"1.jpg"];
    
}

- (void)loadImageWithStr:(NSString*)str{
    
    NSURL *url = [NSURL URLWithString:str];
    //    给imaageView加载网络图片，之前先用1.jpg
    [self.channelImage sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"1.jpg"]];
    
}

- (void)loadDataWithChannelDic:(NSDictionary*)dic{

    [self loadImageWithStr:dic[@"pic_500"]];
    self.soundCountLabel.text = dic[@"sound_count"];
    self.attentionCountLabel.text = dic[@"follow_count"];
    self.shareCountLabel.text = dic[@"share_count"];
   // NSLog(@"dic  222222   %@",dic);
    
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    
    NSString *user_id = [userDefault valueForKey:@"u_id"];
    
    BOOL success = [InSoundFavouriteTool selectchannel:dic[@"id"] WithUser_id:user_id];
    if (success) {
        self.attentionBtn.selected = YES;
    }
    
    
}


- (IBAction)shareBtnClick:(id)sender {
    if ([AppDelegate shareAppdelegate].canConnectedToTheInternet) {
        NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
        //    [userDefault setValue:@"11111" forKey:@"u_id"];
        
        NSString *user_id = [userDefault valueForKey:@"u_id"];
        //用代理的方法
        if (user_id == nil) {
            if ([self.delegate respondsToSelector:@selector(channelConcernBtn)]) {
                [self.delegate channelConcernBtn];
            }
            
        }else {
    [UMSocialSnsService presentSnsIconSheetView:[AppDelegate shareAppdelegate].window.rootViewController
                                         appKey:@"507fcab25270157b37000010"
                                      shareText:@"你要分享的文字"
                                     shareImage:[UIImage imageNamed:@"icon.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,nil]
                                       delegate:self];

            NSLog(@"分享");
        }
    }else {
            [self showAlertView:@"当前网络不可用"];
        }
}
#pragma mark - 封装UIAlertView方法，直接调用就可以显示提示
-(void)showAlertView:(NSString *)string {
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:string delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
    [alertView show];
    
}
- (IBAction)focusonBtnClick:(id)sender {
    if ([AppDelegate shareAppdelegate].canConnectedToTheInternet) {

    NSLog(@"关注");
    
    
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    //    [userDefault setValue:@"11111" forKey:@"u_id"];
    
    NSString *user_id = [userDefault valueForKey:@"u_id"];
    
    
    //用代理的方法
    if (user_id == nil) {
        if ([self.delegate respondsToSelector:@selector(channelConcernBtn)]) {
            [self.delegate channelConcernBtn];
        }
        
    }else {
        if (self.attentionBtn.selected == NO) {
            self.attentionBtn.selected = YES;
            self.attentionCountLabel.text = [NSString stringWithFormat:@"%ld",[self.attentionCountLabel.text integerValue]+1];
        }else {
            self.attentionBtn.selected = NO;
            self.attentionCountLabel.text = [NSString stringWithFormat:@"%ld",[self.attentionCountLabel.text integerValue]-1];
        }
        
    }
    }else {
        [self showAlertView:@"当前网络不可用"];
    }


}
- (IBAction)randomBtnClick:(id)sender {
    NSLog(@"随机");
}

@end
